package VLSys;

import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import javax.swing.*;
import java.util.Calendar;
import java.text.SimpleDateFormat;


public class MainModule extends JPanel {
    JButton leftNavig[] = new JButton[4];
    ImageStore bg;
    ImageIcon transactionButton = new ImageIcon("images/main_module/transaction_button1.jpg");
    ImageIcon managementButton = new ImageIcon("images/main_module/management_button1.jpg");
    ImageIcon reportsButton = new ImageIcon("images/main_module/reports_button1.jpg");
    ImageIcon logoutButton = new ImageIcon("images/main_module/logout_button1.jpg");
    ImageIcon transactionButton2 = new ImageIcon("images/main_module/transaction_button2.jpg");
    ImageIcon managementButton2 = new ImageIcon("images/main_module/management_button2.jpg");
    ImageIcon reportsButton2 = new ImageIcon("images/main_module/reports_button2.jpg");
    ImageIcon logoutButton2 = new ImageIcon("images/main_module/logout_button2.jpg");
    TransactionModule transaction;
    ManagementModule manage;
    ReportsModule reports;
    private JTextField _timeField;
    
    MainPanel mainScreen;
                
    ManagementServiceAdd addSer;
    ManagementServiceEdit editSer;
    ManagementUserAdd addNew;
    ManagementUserEdit editNew;
    ManagementVehicleAdd addVeh;
    ManagementVehicleEdit editVeh;

    ReportsExpenses reportsExpenses;
    ReportsFinancial reportsFinancial;
    ReportsServices reportsServices;
    ReportsUsers reportsUsers;
    ReportsTransactions reportsTransactions;
    ReportsVehicles reportsVehicles;

    TransactionExpense transactionExpense;
    TransactionNew transactionNew;
    TransactionEdit transactionEdit;
    
   

public MainModule(JFrame frame){
    setVisible(true);
    setLayout(null);
    setFocusable(true);
    setBackground(null);
    
    
    _timeField = new JTextField(5);
    _timeField.setEditable(false);
    _timeField.setFont(new Font("sansserif", Font.PLAIN, 12));
    _timeField.setForeground(Color.WHITE);
    _timeField.setBackground(Color.BLACK);
    _timeField.setHorizontalAlignment(JTextField.CENTER);
    _timeField.setBorder(null);


    leftNavig[0] = new JButton();
    leftNavig[0].setIcon(transactionButton);
    leftNavig[0].setRolloverIcon(transactionButton2);
    leftNavig[0].setBackground(null);
    leftNavig[0].setOpaque(false);
    leftNavig[1] = new JButton();
    leftNavig[1].setIcon(managementButton);
    leftNavig[1].setRolloverIcon(managementButton2);
    leftNavig[1].setBackground(null);
    leftNavig[1].setOpaque(false);
    leftNavig[2] = new JButton();
    leftNavig[2].setIcon(reportsButton);
    leftNavig[2].setRolloverIcon(reportsButton2);
    leftNavig[2].setBackground(null);
    leftNavig[2].setOpaque(false);
    leftNavig[3] = new JButton();
    leftNavig[3].setIcon(logoutButton);
    leftNavig[3].setRolloverIcon(logoutButton2);
    leftNavig[3].setBackground(null);
    leftNavig[3].setOpaque(false);


    leftNavig[0].setBounds(9,145,166,55 );
    leftNavig[1].setBounds(8,208,166,55 );
    leftNavig[2].setBounds(8,270,166,55 );
    leftNavig[3].setBounds(8,331,166,55 );
    
    mainScreen = new MainPanel();
    mainScreen.setBounds(176,87,615,491);
            
    addNew = new ManagementUserAdd(frame);
    addNew.setBounds(176,118,618,442);
    editNew = new ManagementUserEdit(frame);
    editNew.setBounds(176,118,618,442);
    addSer = new ManagementServiceAdd(frame);
    addSer.setBounds(176,118,618,442);
    addVeh = new ManagementVehicleAdd(frame);
    addVeh.setBounds(176,118,618,442);
    editSer = new ManagementServiceEdit(frame);
    editSer.setBounds(176,118,618,442);
    editVeh = new ManagementVehicleEdit(frame);
    editVeh.setBounds(176,118,618,442);

    reportsExpenses = new ReportsExpenses(frame);
    reportsExpenses.setBounds(176,118,618,442);
    reportsFinancial = new ReportsFinancial(frame);
    reportsFinancial.setBounds(176,118,618,442);
    reportsServices = new ReportsServices(frame);
    reportsServices.setBounds(176,118,618,442);
    reportsUsers = new ReportsUsers(frame);
    reportsUsers.setBounds(176,118,618,442);
    reportsTransactions = new ReportsTransactions(frame);
    reportsTransactions.setBounds(176,118,618,442);
    reportsVehicles = new ReportsVehicles(frame);
    reportsVehicles.setBounds(176,118,618,442);

    transactionExpense = new TransactionExpense(frame);
    transactionExpense.setBounds(176,118,618,442);
    transactionNew = new TransactionNew(frame);
    transactionNew.setBounds(176,118,618,442);
    transactionEdit = new TransactionEdit(frame);
    transactionEdit.setBounds(176,118,618,442);

    int i;

    for(i=0;i<=3;i++)
    {
        leftNavig[i].setBackground(Color.white);
    }
        
    transaction = new TransactionModule();
    transaction.setBounds(177,88,615,29);

    manage = new ManagementModule();
    manage.setBounds(177,88,615,29);

    reports = new ReportsModule();
    reports.setBounds(177,88,615,29);

    _timeField.setBounds(6,538,162,23);
    bg = new ImageStore("images/main_module/main_frame.png");

    //Left Navigation Buttons
    add(leftNavig[0]);
    add(leftNavig[1]);
    add(leftNavig[2]);
    add(leftNavig[3]);
    
    //Main Screen
    add(mainScreen);

    //Modules
    add(transaction);
    add(manage);
    add(reports);

    //Management Module Panels
    add(addNew);
    add(editNew);
    add(addSer);
    add(addVeh);
    add(editSer);
    add(editVeh);

    //Reports Module Panels
    add(reportsExpenses);
    add(reportsFinancial);
    add(reportsServices);
    add(reportsUsers);
    add(reportsTransactions);
    add(reportsVehicles);

    //Transaction Module Panels
    add(transactionExpense);
    add(transactionNew);
    add(transactionEdit);


    add(_timeField);
    javax.swing.Timer t = new javax.swing.Timer(1000, new ClockListener());
    t.start();
       
    }

public void paint(Graphics g){
   super.paint(g);
   Graphics2D backg2 = (Graphics2D)g;


   backg2.drawImage(bg.getImage(), 0, 0, this);
   
   

   Toolkit.getDefaultToolkit().sync();
   g.dispose();

}

class ClockListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        _timeField.setText(now("EEE MM/dd/yy h:mm:ss a"));
    }
}

public static String now(String dateFormat) {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    return sdf.format(cal.getTime());
    }
}
